package com.fengye.school.model.school;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fengye.school.model.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import java.util.Set;

/**
 * 学院
 */
@Table(name = "tb_s_school")
@org.hibernate.annotations.Table(appliesTo = "tb_s_school", comment = "学院表")
@Entity
@Getter
@Setter
public class School extends BaseEntity {

    /**
     * 中文名称
     */
    @Column(name = "title", columnDefinition = "varchar(255) comment '学院中文名称'")
    private String title;


    /**
     * 英文名称
     */
    @Column(name = "title_en", columnDefinition = "varchar(255) comment '学院英文名称'")
    private String titleEn;

    @Column(name = "sketch", columnDefinition = "varchar(255) comment '学院简称'")
    private String sketch;

    @Column(name = "`introduction`", columnDefinition = "varchar(255) comment '学院简介'")
    private String introduction;

    /**
     * 下属专业/学科
     */
    @JsonIgnore
    @OneToMany(targetEntity = Major.class, mappedBy = "school", fetch = FetchType.LAZY)
    private Set<Major> majorSet;

    /**
     * 该学院开放的科目
     */
    @JsonIgnore
    @OneToMany(targetEntity = Subject.class, mappedBy = "school", fetch = FetchType.LAZY)
    private Set<Subject> subjectSet;


    public String getSketch() {
        return StringUtils.hasText(this.sketch) ? this.sketch : this.title;
    }

    public void setSketch(String sketch) {
        this.sketch = StringUtils.hasText(sketch) ? sketch : this.title;
    }
}
